#案例一
# from pydantic import BaseModel,Field
# from langchain_core.tools import StructuredTool
#
# class CalculatorInput(BaseModel):
#     a:int = Field(description="第一个参数")
#     b:int = Field(description="第二个参数")
#
# def multiply(a: int, b: int) -> int:
#     """Multiply two numbers together."""
#     return a * b
#
# calculator = StructuredTool.from_function(
#     func=multiply,
#     name="multiply",
#     description="乘法计算器",
#     args_schema=CalculatorInput,
#     return_direct=True,
# )
#
# print("工具名称:",calculator.name)
# print("工具描述:",calculator.description)
# print("工具参数:",calculator.args)
# print("工具返回值:",calculator.return_direct)
# print("工具详细的schema:",calculator.args_schema.model_json_schema())
#
# print(calculator.invoke({"a": 2, "b": 3}))


#案例二

from pydantic import BaseModel,Field
from typing import Type
from langchain_core.tools import BaseTool

class CalculatorInput(BaseModel):
    a:int = Field(description="第一个参数")
    b:int = Field(description="第二个参数")

class CustomCalculatorTool(BaseTool):
    name:str = "Calculator"
    description:str = "当你需要计算数学问题时候使用"
    args_schema : Type[BaseModel] = CalculatorInput
    return_direct:bool = True
    def _run(self,a:int,b:int) -> str:
        """试用攻击"""
        return a * b

calculator = CustomCalculatorTool()

print("工具名称:",calculator.name)
print("工具描述:",calculator.description)
print("工具参数:",calculator.args)
print("工具返回值:",calculator.return_direct)
print("工具详细的schema:",calculator.args_schema.model_json_schema())
